1201B - Zero Array - CodeForces Solution


greedy math *1500

Please click on ads to support us..

Python Code:

input()
a=list(map(int, input().split()))
s=sum(a)
if s%2 or max(a)>s//2:
    print("NO")
else:
    print("YES")

C++ Code:

//Jai Shree Ram
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;

#define int long long int
#define pb push_back
#define vi vector<int>
#define endl "\n"
#define all(p) p.begin(), p.end()
#define rep(i,l,r) for(int i=l;i<r;i++)
#define pin pair<int,int>
#define vpin vector<pin>
#define yes() cout<<"YES"<<endl
#define no() cout<<"NO"<<endl
const int N = 1e9+7;
const int M = 1e6+1;
int is_prime[M];
void sieve()
{
  int maxN=1e6;
  for(int i=1;i<=maxN;i++) is_prime[i]=1;
  is_prime[0]=is_prime[1]=0;
  
  for(int i=2;i*i<=maxN;i++)
  {
    if(is_prime[i])
    {
      for(int j=i*i;j<=maxN;j+=i)
      is_prime[j]=0;
    }
  }
}

int power(int x,int n)
{
    int var = 1;
    while(n>0)
    {
        if(n&1)
        {
            var = var*x;
            n--;
        }
        else
        {
            x*=x;
            n/=2;
        }
        
    }
    return var;
    
}

int binary_search(vector<int>&v,int n,int x)
{
    int low = 0;
    int high = n-1;
    int mid;
    while(high-low>1)
    {
        mid = (low+high)/2;
        if(x==v[mid])
        return -1;
        else if(x>v[mid])
        {
            low = mid + 1;
        }
        else if(x<v[mid])
        {
            high = mid-1;
        }
    }
    if(x==v[high]||x==v[low])
    return -1;
    else
    {
        if(x>v[high])
        return high+1;
        else if(x<v[low])
        return low;
        else 
        return low+1;
    }
}


int powermod(int a, int b, int m)
{
    if (b == 0) return 1;
    int k = powermod(a, b / 2, m);
    k = k * k;
    k %= m;
    if (b & 1) k = (k * a) % m ;
    return k;
}
 
int inverse(int a, int mod) {
    return powermod(a, mod - 2, mod);
}

int kadane(vector<int>&v,int n)
{
  int current =0,maximum=0;
  for(int i=0;i<n;i++)
  {
    current+=v[i];
    if(current<0)
    current=0;
    maximum = max(maximum,current);
  }
  return maximum;
}



int32_t main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vi a(n);
	rep(i,0,n)
	cin>>a[i];
	sort(all(a));
	int sum=0;
	rep(i,0,n)
	sum+=a[i];
	if(sum%2==0&&a[n-1]<=sum-a[n-1])
	yes();
	else
	no();
	return 0;
}




Comments

Submit
0 Comments
More Questions

123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum